package server.phone.dao;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.utopia84.model.Area;
import com.utopia84.model.Contact;

/**
 * @author utopia
 * 
 */
public class ContactDAO {
	DBHelper manager;
	String sql = "";
	ResultSet rs;

	public ContactDAO() throws IOException, ClassNotFoundException, SQLException {
		manager = DBHelper.createInstance();
	}

	/**
	 * 返回所有顾客信息
	 * 
	 * @return
	 * @throws SQLException
	 */
	public List<Contact> getAllContact() throws SQLException {
		List<Contact> contacts = new ArrayList<Contact>();
		Contact contact = new Contact();
		sql = "select * from Contact";
		Object[] params = new Object[] {};
		manager.connectDB();
		rs = manager.executeQuery(sql, params);
		while (rs.next()) {
			contact = new Contact();
			contact.setName(rs.getString("Name"));
			contact.setPhone(rs.getString("Phone"));
			contact.setAdd_Number(rs.getString("Add_Number"));
			contact.setAdd_City(rs.getString("Add_City"));
			contacts.add(contact);
		}
		manager.closeDB();
		return contacts;
	}
}
